//! Core message types.

use aspect_codec::prelude::*;

#[derive(Clone, Debug)]
pub struct Msg {
    /// UTC UNIX millis timestamp of when the message was created.
    timestamp: u64,

    /// Body of the message.
    data: Vec<u8>,
}

impl Msg {
    pub fn new(timestamp: u64, data: Vec<u8>) -> Self {
        Self { timestamp, data }
    }

    pub fn timestamp(&self) -> u64 {
        self.timestamp
    }

    pub fn data(&self) -> &[u8] {
        &self.data
    }

    pub fn into_data(self) -> Vec<u8> {
        self.data
    }
}

aspect_codec::inst_semimanual_codec! {
    Msg {
        timestamp field u64,
        data frombuf Vec<u8>
    }
}

#[derive(Clone, Debug)]
pub struct MsgSummary {
    timestamp: u64,
    data_hash: [u8; 32],
}

aspect_codec::inst_semimanual_codec! {
    MsgSummary {
        timestamp field u64,
        data_hash field [u8; 32]
    }
}
